/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-09 17:59:58
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-10 08:47:07
 * @Description: file content
 */

#include <setjmp.h>
#include <signal.h>
#include <unistd.h>

static jmp_buf env_alrm;
static void sig_alarm(int signo)
{
    longjmp(env_alrm, 1);
}

unsigned int sleep2(unsigned int seconds)
{
    if (signal(SIGALRM, sig_alarm) == SIG_ERR)
        return seconds;

    if (setjmp(env_alrm) == 0)
    {
        alarm(seconds);
        pause();
    }

    return alarm(0);
}
